/**
*@Author      :anlzou
*@Date        :9:32 2021/5/5
*@Github      :https://github.com/anlzou
*@Description :
*/
package com.anlzou.streamClass;

import java.util.List;
import java.util.stream.Collectors;

public class MakeStream2ways {
    private List<String> filtered = null;
    private List<Integer> squaresList = null;

    /*---------------------------part one----------------------------------
     * use stream() function
     */
    public void setFiltered(List<String> strings){
         filtered = strings.stream().filter(string-> !string.isEmpty()).collect(Collectors.toList());
    }

    public void setSquaresList(List<Integer> numbers){
        squaresList = numbers.stream().map(i -> i*i).distinct().collect(Collectors.toList());
    }

    public void dispFiltered(){
        System.out.println(filtered);
    }

    public void dispSquaresList(){
        System.out.println(squaresList);
    }

    /*----------------------part two-------------------------
     * use parallelStream() function
     * parallelStream 是流并行处理程序的代替方法。
     */
    public long CountIsEmpty(List<String> strings){
        long count = strings.parallelStream().filter(string -> string.isEmpty()).count();
        return count;
    }
}
